package com.test.io.printStreamWriter;

import org.junit.Test;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @version 1.0
 * @Author: 许啸林 字符打印流
 * @Date: 2021/6/4 14:23
 */
public class PrintWriterDemo {
    // 向文件/ 控制台写入字符数据
    @Test
    public void writeDemo() {
        PrintWriter printWriter = null;
        try {
           printWriter = new PrintWriter(new FileWriter("d:printWriter.text"));
           printWriter.println("小时不识月,呼作白玉盘");
           printWriter.write("又疑瑶台镜,飞在青云端");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(printWriter != null) {
                // printWriter 属于处理流 close 时会调用 implclose -> flush
                printWriter.close();
            }
        }
    }
}
